'use strict';
app.controller('HomeCtrl', function($scope,HomeService,$ionicSlideBoxDelegate,$ionicFilterBar,$state,ShoppingService) {
  //首页banner
  ShoppingService.getCarousel(1).then(function (data) {
    //console.log(data)
    $scope.banner = data;
    $ionicSlideBoxDelegate.update();
  })
  //四个展示图片
  ShoppingService.getActivity().then(function (data) {
    for(var key in data){
      var item = data[key];
      switch (item.type){
        case "0":
          $scope.BargainPriceUrl = item.picture;
          break;
        case "1":
          $scope.GroupBuyUrl = item.picture;
          break;
        case "2":
          $scope.ValuebleUrl = item.picture;
          break;
        case "3":
          $scope.BrandListUrl = item.picture;
          break;
        default :
              break;
      }
    }
  })
  ShoppingService.getBanner(1,5).then(function (data) {
    console.log(data)
    $scope.goodsBannerInHome = data;
  })

  /////我是分割线------------------------------------------
  HomeService.getGoodsBanner().then(function (data) {
    if( !data || data.length === 0 ) return;
    $scope.goodsbanner = data;
    $ionicSlideBoxDelegate.update();
    $ionicSlideBoxDelegate.loop(true);
  });
  /*搜索*/
  $scope.goSearch = function () {
    $scope.showNavBar =false;
    $state.go('search')
  };



  /*店铺*/
  $scope.goStore = function () {
    $scope.showNavBar =false;
    $state.go('store')
  };
  $scope.SearchIndex = 0;
  $scope.showSearchType=function(index){
    if($scope.SearchIndex == index){
      return;
    }
    $scope.SearchIndex = index;
  };
  $scope.storeIndex = 0;
  $scope.showStoreType=function(index){
    if($scope.storeIndex == index){
      return;
    }
    $scope.storeIndex = index;
  };
  $scope.showStoreSelect=false;
  $scope.goStoreSelect =function(){
    $scope.showStoreSelect =! $scope.showStoreSelect
  };
  $scope.storeSideList = [
    { value: "最新排序" },
    {  value: "人气排序" }
  ];
  $scope.data = {
    storeSide: '最新排序'
  };

  /*分类*/
  $scope.goDivideMore =function(){
    $state.go("divideMore")
  };


  $scope.showDivideSelect=false;
  $scope.goStoreSelect =function(){
    $scope.showStoreSelect =! $scope.showStoreSelect
  };
  $scope.storeSideList = [
    { value: "最新排序" },
    { value: "人气排序" },
    { value: "收藏排序" },
    { value: "价格从低到高" },
    { value: "价格从高到低" }
  ];
  $scope.data = {
    storeSide: '最新排序'
  };

  $scope.goMore = function () {
    $scope.showNavBar =false;
    $state.go('goodsMoreDetail')
  };
  $scope.panelIndex = 1;
  $scope.showType=function(index){
    if($scope.panelIndex == index){
      return;
    }
    $scope.panelIndex = index;
  };
  $scope.panelFirstSubIndex = 0;
  $scope.showFirstSubType=function(index){
    if($scope.panelFirstSubIndex == index){
      return;
    }
    $scope.panelFirstSubIndex = index;
  };
  $scope.GoodsShow =false;
  $scope.toggleGoodsGroup = function() {
    $scope.GoodsShow= !$scope.GoodsShow;
  };
  $scope.panelSecondSubIndex = 0;
  $scope.showSecondSubType=function(index){
    if($scope.panelSecondSubIndex == index){
      return;
    }
    $scope.panelSecondSubIndex = index;
  };

  /*确认订单*/
  $scope.goCheckBill = function () {
    $state.go("checkBill")
  };


  /*支付*/
  $scope.goPayBill = function(){
    $state.go("payBill")
  };

  /*发票信息*/
  $scope.goBill = function(){
    $state.go("bill")
  };
  $scope.bgImg =true;
  $scope.selectBg = function(){
    $scope.bgImg = !$scope.bgImg;
  };




})
